package com.testing.runner;

import com.testing.common.AutoTools;
import com.testing.common.ExcelReader;
import com.testing.common.ExcelWriter;
import com.testing.common.Report;
import com.testing.inter.InterKeyWord;
import org.apache.poi.ss.usermodel.Sheet;

import java.util.List;

/**
 * @Classname RunInterDDT
 * @Description 类型说明
 * @Date 2022/11/9 20:18
 * @Created by 特斯汀Roy
 */
public class RunInterDDT {
    public static final int ASSERT_COL=7;
    public static final int KEY_COL=3;

    public static void main(String[] args) {
        InterKeyWord inter=new InterKeyWord();
        String runDate = AutoTools.dateStr("yyyy-MM-dd HH：mm：ss");
        ExcelReader cases=new ExcelReader("Cases\\InterCases.xlsx");
        ExcelWriter results=new ExcelWriter("Cases\\InterCases.xlsx",
                "Cases\\Result\\resultofInter"+runDate+".xlsx");
        for (int sheetNO = 0; sheetNO < cases.getTotalSheetNo(); sheetNO++) {
            //使用指定的sheet页
            cases.useSheetByIndex(sheetNO);
            results.useSheetByIndex(sheetNO);
            System.out.println("-----------------------当前执行到的sheet页是："+cases.getSheetName(sheetNO));

            for (int rowNO = 0; rowNO < cases.getRowNo(); rowNO++) {
                List<String> rowContent = cases.readLine(rowNO);
                System.out.println("*********当前执行到第"+rowNO+"行，内容是"+rowContent);
                //是真正的用例行才执行,也就是第一二列去掉空格之后，长度小于1。
                if(rowContent.get(0)!=null&&rowContent.get(1)!=null
                        &&rowContent.get(0).trim().length()<2&&rowContent.get(1).trim().length()<2) {
                    //运行关键字方法
                    boolean runRes = AutoTools.invokeKeyWord(inter, rowContent, KEY_COL);
                    //运行断言方法，只有写了断言关键字才运行
                    if(rowContent.get(ASSERT_COL).trim().length()>1){
                        //断言之后获取的返回结果
                        runRes = AutoTools.invokeKeyWord(inter, rowContent, ASSERT_COL);
                    }
                    //写入返回结果
                    if(runRes){
                        results.writeCell(rowNO,10,"PASS");
                        results.writeCell(rowNO,11,inter.getResult());
                    }else{
                        results.writeFailCell(rowNO,10,"FAIL");
                        results.writeFailCell(rowNO,11,inter.getResult());
                    }
                }
            }

        }
        cases.close();
        results.save();
        //发送邮件报告
        Report.sendreport("Cases\\Result\\resultofInter"+runDate+".xlsx",runDate);
    }



}
